<?php
// +----------------------------------------------------------------------
// | PHP [ JUST YOU ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2017 http://www.jyphp.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: FlyingPig <flyingpigfp@163.com>
// +----------------------------------------------------------------------

namespace App\Http\Controllers;

use App\Exceptions\ApiException;
use App\Logic\QuicklyGrabLogic;
use App\Model\QuicklyGrab\QuicklyGrabList;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;

class QuicklyGrab extends Base
{

    /**
     * @api 快抢赛列表
     * @return null|string|string[]
     */
    public function index()
    {
        return $this->returnData(
            QuicklyGrabList::where('status', '>', 0)->orderBy('picture_type','desc')->orderBy('priority', 'desc')->get([
                'id',
                'name',
                'status',
                'icon_url',
                'big_icon_url',
                'desc',
                'status',
                'start_time',
                'end_time',
                'create_time',
                'expire_time',
                'type',
                'picture_type'
            ])
        );
    }


    /**
     * @api 刷新快抢赛的基本次数和本日充值次数
     * @return null|string|string[]
     * @throws ApiException
     */
    public function ticket()
    {
        return $this->returnData(
            QuicklyGrabLogic::instance()->ticketLogic($this->uid)
        );
    }


    /**
     * @api 钻石兑换快抢赛的基本次数
     * @return null|string|string[]
     * @throws ApiException
     */
    public function exchangeTicket()
    {
        return $this->returnData(
            QuicklyGrabLogic::instance()->exchangeTicketLogic($this->param['is_return'], $this->uid)
        );
    }


    public function prize()
    {
        return $this->returnData(
            QuicklyGrabLogic::instance()->prize($this->param['length'])
        );
    }


    public function rec()
    {
        return $this->returnData(
            QuicklyGrabLogic::instance()->recLogic($this->param['id'])
        );
    }

}